export default function flattenNavigationTree(navigations) {
  const rows = [];

  const traverse = (items, position, parent_id = null) => {
    items.forEach((item, index) => {
      const { children, ...rest } = item;
      rows.push({ ...rest, parent_id, position, sort: index + 1, });
      if (children && children.length > 0) {
        traverse(children, position, item.id);
      }
    });
  };

  for (const position in navigations) {
    traverse(navigations[position], position);
  }

  return rows;
}
